package by.wind.drebedengi.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.widget.Spinner;

public class PrefUtil {

	private static SharedPreferences itsSettings;
	private static String prefix = "element";
	private static int DEFAULT_VALUE = 0;
	
	public static void saveSpinnerState(Context aContext, Spinner element) {
		itsSettings = PreferenceManager.getDefaultSharedPreferences(aContext.getApplicationContext());
		Editor editor = itsSettings.edit();
		editor.putInt(prefix+element.getId(), element.getSelectedItemPosition());
		editor.commit();
	}
	
	public static int loadSpinnerState(Context aContext, Spinner element) {
		itsSettings = PreferenceManager.getDefaultSharedPreferences(aContext.getApplicationContext());
		return itsSettings.getInt(prefix+element.getId(), DEFAULT_VALUE);
	}
}
